package com.xfanonymous.cloud.api;

import com.xfanonymous.cloud.entities.PayDTO;
import com.xfanonymous.cloud.resp.ResultData;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * @auther xfanonymous
 * @create 2023-12-25 11:27
 *
 * OpenFeign
 * 1. @FeignClient("service-name") 为目标服务端提供统一对外的端口方法，value为注册中心的服务名
 * 2. 为被调用服务 cloud-payment-service 提供对外端口
 *
 * Resilience4J
 * 1. CircuitBreaker 断路器功能验证
 *
 * Gateway
 * 1. 修改@FeignClient(value = "cloud-gateway")为网关服务名
 */
//@FeignClient(value = "cloud-payment-service")
@FeignClient(value = "cloud-gateway")
public interface PayFeignApi
{
    /**
     * 新增一条支付相关流水记录
     */
    @PostMapping(value = "/pay/add")
    public ResultData addPay(@RequestBody PayDTO payDTO);

    /**
     * 按照主键记录查询支付流水信息
     */
    @GetMapping(value = "/pay/get/{id}")
    public ResultData getPayInfo(@PathVariable("id") Integer id);

    /**
     * openfeign天然支持负载均衡，获取当前提供服务的服务端的配置信息
     */
    @GetMapping(value = "/pay/get/info")
    public String getServiceInfo();

    /**
     * Resilience4J CircuitBreaker 断路器功能验证
     */
    @GetMapping(value = "/pay/circuit/{id}")
    public String myCircuit(@PathVariable("id") Integer id);

    /**
     * Resilience4J Bulkhead
     */
    @GetMapping(value = "/pay/bulkhead/{id}")
    public String myBulkhead(@PathVariable("id") Integer id);


    /**
     * Resilience4j RateLimit
     */
    @GetMapping(value = "/pay/ratelimit/{id}")
    public String myRateLimit(@PathVariable("id") Integer id);


    /**
     * Micrometer + ZipKin 分布式链路追踪
     */
    @GetMapping(value = "/pay/micrometer/{id}")
    public String myMicrometer(@PathVariable("id") Integer id);


    /**
     * GateWay 网关路由测试1
     */
    @GetMapping(value = "/pay/gateway/get/{id}")
    public ResultData getById(@PathVariable("id") Integer id);

    /**
     * GateWay 网关路由测试2
     * @return
     */
    @GetMapping(value = "/pay/gateway/info")
    public ResultData<String> getGatewayInfo();

}
